package msg

import (
	"math/rand"
	"strconv"
	"time"
)

const (
	CARDS_TYPE_SINGLE     = 1  //单张
	CARDS_TYPE_DOUBLE     = 2  //对子
	CARDS_TYPE_3ON0       = 3  //3不带
	CARDS_TYPE_3ON1       = 4  //3带1
	CARDS_TYPE_3ON2       = 5  //3带2
	CARDS_TYPE_4ON1       = 6  //4带1
	CARDS_TYPE_4ON2       = 7  //4带2
	CARDS_TYPE_LINE       = 8  //顺子
	CARDS_TYPE_MULT3ON0   = 9  //组合3不带
	CARDS_TYPE_MULT3ON1   = 10 //组合3带1
	CARDS_TYPE_MULT3ON2   = 11 //组合3带2
	CARDS_TYPE_MULT4ON1   = 12 //组合4带1
	CARDS_TYPE_MULT4ON2   = 13 //组合4带2
	CARDS_TYPE_MULTDOUBLE = 14 // 连对
	CARDS_TYPE_BOOM       = 15 //炸弹
	CARDS_TYPE_KBOOM      = 16 //王炸
	CARDS_TYPE_ERROR      = 0  //错误的出牌组合
)

type Card struct {
	//3,4,5,6,7,8,9,10,11-j,12-q,13-k,14-a,15-2,16-lj,17-bj
	Num int
	//0,1,2,3对应桃星梅方,4为大小王特有
	Types int
}

var cards [54]Card

func (c *Card) ToString() string {
	return strconv.Itoa(c.Num) + "--" + strconv.Itoa(c.Types)
}

func init() {
	cards = [54]Card{}
	ind := 0
	for i := 3; i <= 15; i++ {
		for j := 0; j <= 3; j++ {
			cards[ind] = Card{Num: i, Types: j}
			ind++
		}
	}
	cards[52] = Card{Num: 16, Types: 4}
	cards[53] = Card{Num: 17, Types: 4}
}

func RandomCards() []Card {
	rand.Seed(time.Now().Unix())
	result := make([]Card, 0, 0)
	for _, o := range rand.Perm(54) {
		result = append(result, cards[o])
	}
	return result
}
